package com.dong.rwmysql.controller;

import com.dong.rwmysql.bean.UserEntity;
import com.dong.rwmysql.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;

@RestController
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("/listUser")
    public List<UserEntity> listUser() {
        List<UserEntity> users = userService.findAll();
        return users;
    }

    @RequestMapping("/insertUser")
    public void insertUser() {
        UserEntity userEntity = new UserEntity();
        Random random = new Random();
        userEntity.setUser_id(random.nextInt());
        userEntity.setAccount("22222");
        userEntity.setNickname("lxrlxrlxr");
        userEntity.setPassword("123");
        userService.insertUser(userEntity);
    }

}
